package study;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author 金贵权
 * @Date 2023/6/12 14:44
 **/
public class flatMapDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("hello");
        list.add("world");
        List<String[]> collect = list.stream().map(x -> x.split("")).distinct().collect(Collectors.toList());
        System.out.println(collect);
        List<Stream<String>> collect1 = list.stream().map(x -> x.split("")).map(Arrays::stream).distinct().collect(Collectors.toList());
        System.out.println(collect1);
        List<String> collect2 = list.stream().map(x -> x.split("")).flatMap(x->Arrays.stream(x)).distinct().collect(Collectors.toList());
        List<String> collect3 = list.stream().map(x -> x.split("")).flatMap(Arrays::stream).distinct().collect(Collectors.toList());
        System.out.println(collect2);
        String name = "你好你好";
        String[] split = name.split("");
        for (String s : split) {
            System.out.println(s);
        }
        System.out.println(split);
    }
}
